package com.gpframework.module.manufacture.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.manufacture.domain.GpProductionDetails;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @ClassName GpProductionDetailsReq
 * @Author gpframework
 * @Date 2023-12-11
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpProductionDetailsReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("订单号")
     private String sn;
     @ApiModelProperty("染厂id")
     private Long dyeingFactoryId;
     @ApiModelProperty("染厂名称")
     private String dyeingFactoryName;
     @ApiModelProperty("胚布基础表id")
     private Long supplierGreyClothId;
     @ApiModelProperty("供应商名称")
     private String supplierName;
     @ApiModelProperty("供应商胚布品名")
     private String supplierGreyClothName;
     @ApiModelProperty("产品基础表id")
     private Long produceProductId;
     @ApiModelProperty("产品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String colour;
     @ApiModelProperty("颜色对照表id")
     private Long colourComparisonId;
     @ApiModelProperty("染厂色号（代码）")
     private String factoryColourCode;
     @ApiModelProperty("颜色备注表id")
     private Long colourRemarksId;
     @ApiModelProperty("颜色备注")
     private String colourRemarks;
     @ApiModelProperty("数量")
     private Integer quantity;
     @ApiModelProperty("缸数")
     private Integer dyeVatQuantity;
     @ApiModelProperty("做货要求明细表id")
     private Long makingGoodsRequirementDetailsId;
     @ApiModelProperty("手感")
     private String feel;
     @ApiModelProperty("下机幅宽")
     private String lowerMachineWidth;
     @ApiModelProperty("克重")
     private String gramWeight;
     @ApiModelProperty("打码规格表id")
     private Long codingSpecificationsId;
     @ApiModelProperty("打码规格")
     private String codingSpecifications;
     @ApiModelProperty("标签规格")
     private String tagSpecifications;
     @ApiModelProperty("送货地基础表id")
     private Long deliveryLocationId;
     @ApiModelProperty("送货地")
     private String deliveryLocation;
     @ApiModelProperty("物流基础表id")
     private Long logisticsId;
     @ApiModelProperty("物流")
     private String logistics;
     @ApiModelProperty("物流基础表id")
     private Long makingGoodsRemarksId;
     @ApiModelProperty("备注")
     private String makingGoodsRemarks;
     @ApiModelProperty("销售员id")
     private Long salesmanId;
     @ApiModelProperty("销售员名称")
     private String salesmanName;
     @ApiModelProperty("是否分享图片： 0否 1是")
     private String imgShareFlag;
     @ApiModelProperty("是否下单： 0否 1是")
     private String placeAnOrderFlag;
     @ApiModelProperty("申请人id")
     private Long applicantId;
     @ApiModelProperty("申请人名称")
     private String applicantName;
     @ApiModelProperty("申请时间")
     private Date applicantTime;
     @ApiModelProperty("跟单人id")
     private Long followUpId;
     @ApiModelProperty("跟单人名称")
     private String followUpName;
     @ApiModelProperty("跟单时间")
     private Date followUpTime;
     @ApiModelProperty("排序")
     private Integer sort;
     @ApiModelProperty("查询条件（订单号/客户名）")
     private String searchName;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date searchDate;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date startTime;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date endTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("回货日期开始时间")
    private Date returnTimeStartTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("回货日期结束时间")
    private Date returnTimeEndTime;
    /** 缸号 */
    @ApiModelProperty("缸号")
    private String dyeVatNo;
    /** 操作人名称 */
    private String operatorName;
    /** 操作人编号 */
    private String operatorNum;

    /** 实际胚布用量 */
    @ApiModelProperty("实际胚布用量")
    private Integer actualGreyUsed;

    /** 胚布库存数量 */
    @ApiModelProperty("胚布库存数量")
    private Integer stockGreyNum;

    /** 胚布剩余数量 */
    @ApiModelProperty("胚布剩余数量")
    private Integer leaveGreyNum;

    @ApiModelProperty("备注基础表id")
    private Long remarksId;

    /** 供应商送货件数 */
    @ApiModelProperty("供应商送货件数")
    private Integer supplierDeliveryQuantity;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpProductionDetails> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias+"create_time");
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (StringUtils.isNotBlank(this.getSn())){
        lqw.like(alias+"sn" ,this.getSn());
        }
        if (this.getDyeingFactoryId() != null){
        lqw.eq(alias+"dyeing_factory_id" ,this.getDyeingFactoryId());
        }
        if (StringUtils.isNotBlank(this.getDyeingFactoryName())){
            lqw.like(alias+"dyeing_factory_name",this.getDyeingFactoryName());
        }
        if (this.getSupplierGreyClothId() != null){
        lqw.eq(alias+"supplier_grey_cloth_id" ,this.getSupplierGreyClothId());
        }
        if (StringUtils.isNotBlank(this.getSupplierName())){
            lqw.like(alias+"supplier_name",this.getSupplierName());
        }
        if (StringUtils.isNotBlank(this.getSupplierGreyClothName())){
            lqw.like(alias+"supplier_grey_cloth_name",this.getSupplierGreyClothName());
        }
        if (this.getProduceProductId() != null){
        lqw.eq(alias+"produce_product_id" ,this.getProduceProductId());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getColour())){
        lqw.eq(alias+"colour" ,this.getColour());
        }
        if (this.getColourComparisonId() != null){
        lqw.eq(alias+"colour_comparison_id" ,this.getColourComparisonId());
        }
        if (StringUtils.isNotBlank(this.getFactoryColourCode())){
        lqw.eq(alias+"factory_colour_code" ,this.getFactoryColourCode());
        }
        if (this.getColourRemarksId() != null){
        lqw.eq(alias+"colour_remarks_id" ,this.getColourRemarksId());
        }
        if (StringUtils.isNotBlank(this.getColourRemarks())){
        lqw.eq(alias+"colour_remarks" ,this.getColourRemarks());
        }
        if (this.getQuantity() != null){
        lqw.eq(alias+"quantity" ,this.getQuantity());
        }
        if (this.getDyeVatQuantity() != null){
        lqw.eq(alias+"dye_vat_quantity" ,this.getDyeVatQuantity());
        }
        if (this.getMakingGoodsRequirementDetailsId() != null){
        lqw.eq(alias+"making_goods_requirement_details_id" ,this.getMakingGoodsRequirementDetailsId());
        }
        if (StringUtils.isNotBlank(this.getFeel())){
        lqw.eq(alias+"feel" ,this.getFeel());
        }
        if (StringUtils.isNotBlank(this.getLowerMachineWidth())){
        lqw.eq(alias+"lower_machine_width" ,this.getLowerMachineWidth());
        }
        if (StringUtils.isNotBlank(this.getGramWeight())){
        lqw.eq(alias+"gram_weight" ,this.getGramWeight());
        }
        if (this.getCodingSpecificationsId() != null){
        lqw.eq(alias+"coding_specifications_id" ,this.getCodingSpecificationsId());
        }
        if (StringUtils.isNotBlank(this.getCodingSpecifications())){
        lqw.eq(alias+"coding_specifications" ,this.getCodingSpecifications());
        }
        if (StringUtils.isNotBlank(this.getTagSpecifications())){
        lqw.eq(alias+"tag_specifications" ,this.getTagSpecifications());
        }
        if (this.getDeliveryLocationId() != null){
        lqw.eq(alias+"delivery_location_id" ,this.getDeliveryLocationId());
        }
        if (StringUtils.isNotBlank(this.getDeliveryLocation())){
        lqw.eq(alias+"delivery_location" ,this.getDeliveryLocation());
        }
        if (this.getLogisticsId() != null){
        lqw.eq(alias+"logistics_id" ,this.getLogisticsId());
        }
        if (StringUtils.isNotBlank(this.getLogistics())){
        lqw.eq(alias+"logistics" ,this.getLogistics());
        }
        if (this.getMakingGoodsRemarksId() != null){
        lqw.eq(alias+"making_goods_remarks_id" ,this.getMakingGoodsRemarksId());
        }
        if (StringUtils.isNotBlank(this.getMakingGoodsRemarks())){
        lqw.like(alias+"making_goods_remarks" ,this.getMakingGoodsRemarks());
        }
        if (this.getSalesmanId() != null){
        lqw.eq(alias+"salesman_id" ,this.getSalesmanId());
        }
        if (StringUtils.isNotBlank(this.getSalesmanName())){
            lqw.like(alias+"salesman_name",this.getSalesmanName());
        }
        if (StringUtils.isNotBlank(this.getImgShareFlag())){
        lqw.eq(alias+"img_share_flag" ,this.getImgShareFlag());
        }
        if (StringUtils.isNotBlank(this.getPlaceAnOrderFlag())){
        lqw.eq(alias+"place_an_order_flag" ,this.getPlaceAnOrderFlag());
        }
        if (this.getApplicantId() != null){
        lqw.eq(alias+"applicant_id" ,this.getApplicantId());
        }
        if (StringUtils.isNotBlank(this.getApplicantName())){
            lqw.like(alias+"applicant_name",this.getApplicantName());
        }
        if (this.getApplicantTime() != null){
        lqw.eq(alias+"applicant_time" ,this.getApplicantTime());
        }
        if (this.getFollowUpId() != null){
        lqw.eq(alias+"follow_up_id" ,this.getFollowUpId());
        }
        if (StringUtils.isNotBlank(this.getFollowUpName())){
            lqw.like(alias+"follow_up_name",this.getFollowUpName());
        }
        if (this.getFollowUpTime() != null){
        lqw.eq(alias+"follow_up_time" ,this.getFollowUpTime());
        }
        if (this.getSort() != null){
        lqw.eq(alias+"sort" ,this.getSort());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.product_name", this.getSearchName()).or().like("gp.colour", this.getSearchName()));
        }
        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
        if (this.getStartTime() != null && this.getEndTime() != null) {
            lqw.between(alias + "applicant_time", this.getStartTime(), this.getEndTime());
        }
        if (this.getReturnTimeStartTime() != null && this.getReturnTimeEndTime() != null) {
            lqw.between("gps.return_time", this.getReturnTimeStartTime(), this.getReturnTimeEndTime());
        }
    }
}
